// schoolclass/mycustomer/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    title_list: [
      { name: "全部好友", is_group: 0 },
      { name: "好友分组", is_group: 1 },
    ],
    page:1,
    list:[],
    open:0,
    is_group:0,
    user_group:[],
    selects:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that.recommend_user()
  },
  recommend_user:function(){
    var that = this
    getApp().request({
            url: getApp().api.schoolclass.recommend_user,
            method: "GET",
            data: {
                  page:that.data.page,
                  is_group:that.data.is_group
            },   
            success: function (res) {
               console.log(res, '数据')
                if(that.data.is_group == 0){
                  for(var i = 0;i<res.user_list.length;i++){
                    that.data.list.push(res.user_list[i])
                    that.setData({
                      list:that.data.list
                    })
                  }
                }else{
                  for(var i = 0;i<res.user_group.length;i++){
                    that.data.user_group.push(res.user_group[i])
                    that.setData({
                      user_group:that.data.user_group
                    })
                  }
                }
              
            }
          });
  },
 // 点击选择好友显示类型
 open_time(e) {
    console.log('e',e)
    var that = this
    that.setData({
      is_group:e.currentTarget.dataset.is_group,
      list:[],
      user_group:[]
    })
    that.recommend_user()
},
  //点击打开分组关闭分组
  select:function(e){
    var that= this
    if(that.data.selects == e.currentTarget.dataset.index){
      that.setData({
        selects:999999999999
      })
    }else{
      that.setData({
        selects:e.currentTarget.dataset.index
      })
    }
  },
// 点击设置跳转到选择分组添加备注页面
get_setting(e) {
  console.log('e',e)
  wx.navigateTo({
    url: '/schoolclass/mycustomer_setting/index?group_id='+e.currentTarget.dataset.group_id+'&user_id='+e.currentTarget.dataset.user_id,
  })
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (e) {
    // console.log(e,'------------')
    // var that = this
    // console.log('78879887878787878787')
    // that.setData({
    //   list:[],
    //   user_group:[]
    // })
    // that.recommend_user()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    that.setData({
      page:that.data.page + 1
    })
   that.recommend_user()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})